package me.ereach;

import me.ereach.model.Employee;
import org.junit.Test;

import java.util.*;

public class TestLambda {
    // 匿名内部类
    @Test
    public void test1() {
        Comparator<Integer> com = new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return Integer.compare(o1, o2);
            }
        };

        TreeSet<Integer> ts = new TreeSet<>(com);
    }

    // Lambda
    @Test
    public void test2() {
        Comparator<Integer> com = (x, y) -> Integer.compare(x, y);

        TreeSet<Integer> ts = new TreeSet<>(com);
    }

    List<Employee> employees = Arrays.asList(
            new Employee("Tom", 28, 4000D),
            new Employee("Jerry", 42, 5200D),
            new Employee("Mary", 28, 4200D),
            new Employee("Kate", 33, 5100D),
            new Employee("Wendy", 29, 4400D)
    );

    public List<Employee> filterEmployees(List<Employee> list) {
        List<Employee> emps = new ArrayList<>();

        for (Employee emp : list) {
            if (emp.getAge() >= 35) {
                emps.add(emp);
            }
        }

        System.out.println(emps);

        return emps;
    }

    // 获取当前公司员工年龄大于35岁的员工信息
    @Test
    public void test3() {
        List<Employee> emps = filterEmployees(employees);

        for (Employee employee : emps) {
            System.out.println(employee.getName());
        }
    }

    
}
